<?php

namespace app\common\model;

use think\Db;
use think\Model;
use think\Validate;

/**
 * 布置作业表模型
 */
class HomeworkAssignmentRelation extends Model
{
    // 表名,不含前缀
    protected $name = 'homework_assignment_relation';

    /**
     * 列表
     */
    public function dataList($dis, $joinTable = null, $joinCondition = null, $joinType = null,$field = '*')
    {
        $res = $this->where([]);
        if ($joinTable && $joinCondition && $joinType) {
            $res->alias('har')
                ->join($joinTable, $joinCondition, $joinType);
        }
        // 遍历条件数组，动态构建查询条件
        foreach ($dis as $field => $condition) {
            if(Validate::is($condition, 'array') && isset($condition[0]) && $condition[0] === 'in') {
                // 处理 IN 条件
                $res->whereIn($field, $condition[1]);
            } else {
                // 普通条件
                $res->where($field, $condition);
            }
        }
        
        return $res->select();
    }
}
